<?php
class Admin_WebsettingController extends Zend_Controller_Action{
	public function init(){
		
	}
	
	public function indexAction(){
		$model = new Application_Model_DbTable_Site();
		$row = $model->fetchRow($model->select()->where('site_name = ?','default'));
		
		$form = new Admin_Form_Site();
		
		$form->populate($row->toArray());
		
		if($this->_request->isPost()){
			$data = $this->_request->getPost();
			if($form->isValid($data)){
				if($form->file_logo->receive() && $form->getValue('file_logo') != '' ){
					$data['site_logo'] = $form->getValue('file_logo');
				}
				
				if($form->file_icon->receive() && $form->getValue('file_icon') != '' ){
					$data['site_icon'] = $form->getValue('file_icon');
				}
				
				$row->setFromArray($data);
				$row->save();
			}
			
			
		}
		$form->site_logo->setAttrib ( 'src', PUBLIC_RESOURCE . '/uploads/images/setting/' . $row->site_logo );
		$form->site_icon->setAttrib ( 'src', PUBLIC_RESOURCE . '/uploads/images/setting/' . $row->site_icon );
		$this->view->form  = $form;
	}
}